package com.xzq.bizimpl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xzq.biz.OrdersBiz;
import com.xzq.dao.OrdersDao;
import com.xzq.entity.Order_State;
import com.xzq.entity.Orders;
import com.xzq.entity.Page;
import com.xzq.entity.User;
@Service
public class OrdersBizImpl implements OrdersBiz {
	@Resource
	private OrdersDao dao;
	@Override
	public Page findAllOrders(Page page) {
		// TODO 自动生成的方法存根
		return null;
	}

	@Override
	public Page findOneUserAllOrders(Page page, User user) {
		page = dao.findOneUserAllOrders(page, user);
		return page;
	}

	@Override
	public Orders findOneOrder(Orders orders) {
		orders = dao.findOneOrder(orders);
		return orders;
	}

	@Override
	public int addOrders(Orders orders) {
		Order_State os = new Order_State();
		os.setId(1);
		orders.setOs(os);
		orders.setFlag(0);
		int count = dao.addOrders(orders);
		return count;
	}

	@Override
	public int modifyOrders(Orders orders) {
		int count = dao.modifyOrders(orders);
		return count;
	}

	@Override
	public int deleteOrders(Orders orders) {
		int count = dao.deleteOrders(orders);
		return count;
	}

	@Override
	public int modifyOrdersByShopCatToOrders(User user) {
		Orders orders = dao.findOneOrdersWhereItIsAShopCat(user);
		int count = -1;
		if(orders!=null){
			orders = dao.findOneOrdersWhereItIsAShopCat(orders.getUser());
			Double sumPrice = dao.findOneOrdersSumPrice(orders);
			orders.setSumPrice(sumPrice);
			orders.setFlag(1);
			count = dao.modifyOrders(orders);
		}
		return count;
	}

	@Override
	public Orders findISHaveShopCat(User user) {
		Orders o = dao.findOneOrdersWhereItIsAShopCat(user);
		return o;
	}

	@Override
	public Double findSumPrice(Orders o) {
		Double sumPrice = dao.findOneOrdersSumPrice(o);
		return sumPrice;
	}

}
